﻿using Bmz.IM.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bmz.IM.AccessDB
{
    public class UserAccess
    {
        private List<UserPO> Users { get; set; }
        public UserAccess()
        {
            Users = new List<UserPO>();
            Users.Add(new UserPO { 
                Id=1,
                UserId="zhangxl",
                UserName="张晓亮",
                Ip = System.Configuration.ConfigurationManager.AppSettings["ServerIp"],
                Port =8001,
                Pwd="123456",
                CurrentState = StructUserState.Offline,
                RegisterDate=DateTime.Now,
                RecentLoginDate=DateTime.Now,
                TodayFeeling="今天天气真好。"
            });
            Users.Add(new UserPO
            {
                Id = 2,
                UserId = "zhangk",
                UserName = "张凯",
                Ip = System.Configuration.ConfigurationManager.AppSettings["ServerIp"],
                Port = 8002,
                Pwd = "123456",
                CurrentState = StructUserState.Offline,
                RegisterDate = DateTime.Now,
                RecentLoginDate = DateTime.Now,
                TodayFeeling = "今天天气真好。"
            });
            Users.Add(new UserPO
            {
                Id = 3,
                UserId = "niex",
                UserName = "聂旭",
                Ip = System.Configuration.ConfigurationManager.AppSettings["ServerIp"],
                Port = 8003,
                Pwd = "123456",
                CurrentState = StructUserState.Offline,
                RegisterDate = DateTime.Now,
                RecentLoginDate = DateTime.Now,
                TodayFeeling = "今天天气真好。"
            });
            Users.Add(new UserPO
            {
                Id = 4,
                UserId = "xiongzy",
                UserName = "熊志勇",
                Ip = System.Configuration.ConfigurationManager.AppSettings["ServerIp"],
                Port = 8003,
                Pwd = "123456",
                CurrentState = StructUserState.Offline,
                RegisterDate = DateTime.Now,
                RecentLoginDate = DateTime.Now,
                TodayFeeling = "今天天气真好。"
            });
        }
        public UserPO GetUserModelByUserId(string userId)
        {
            var query = from p in Users
                        where p.UserId == userId
                        select p;
            return query.LastOrDefault();
        }
        public bool IsExistByUserIdAndPwd(string userId,string pwd)
        {
            var query = from p in Users
                        where p.UserId == userId && p.Pwd==pwd
                        select p;
            return query.Count() > 0;
        }

    }
}
